package com.yugu.park.system.controller;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;

import com.yugu.park.dto.TreeNode;
import com.yugu.park.system.entity.SysDeptEntity;
import com.yugu.park.system.service.SysDeptService;
import com.yugu.util.ResponseUtil;
import com.yugu.util.SearchPage;
import com.github.pagehelper.PageInfo;

/**
 * 部门表
 *
 * @author guxf
 * @email sjzyug@163.com
 * @date 2023-08-19 17:10:48
 */
@Api(tags = {"部门表"})
@RestController
@RequestMapping("system/sysdept")
public class SysDeptController {
    @Autowired
    private SysDeptService service;

    /**
     * 列表
     */

    @ApiOperation(value="分页查询", notes="分页查询")
    @RequestMapping(value = "/page", method = RequestMethod.POST)
    public ResponseUtil.Result<PageInfo<SysDeptEntity>> page (@RequestBody SearchPage<SysDeptEntity> search){
        PageInfo<SysDeptEntity> page = service.page(search);
        return ResponseUtil.addSuccess(page);
    }
	@ApiOperation(value="查看详情", notes="查看详情")
    @GetMapping("/{deptId}")
    public ResponseUtil.Result<SysDeptEntity> info(@PathVariable("deptId") Long deptId){
		SysDeptEntity sysDept = service.getById(deptId);
        return ResponseUtil.addSuccess(sysDept);
    }
    @ApiOperation(value="新增", notes="新增")
    @RequestMapping(value="/save", method= RequestMethod.POST)
    public ResponseUtil.Result<Boolean> save(@RequestBody SysDeptEntity sysDept){
		service.save(sysDept);
         return ResponseUtil.addSuccess(true);
    }
    /**
     * 修改
     */
    @ApiOperation(value="修改", notes="修改")
    @RequestMapping(value="/update", method = RequestMethod.PUT)
    public ResponseUtil.Result<Boolean> update(@RequestBody SysDeptEntity sysDept){
		service.updateById(sysDept);
        return ResponseUtil.addSuccess(true);
    }
    @ApiOperation(value="批量删除", notes="批量删除")
    @RequestMapping(value="/delete", method = RequestMethod.DELETE)
    public ResponseUtil.Result<Boolean> delete(@RequestBody Long[] deptIds){
		service.removeByIds(Arrays.asList(deptIds));
        return ResponseUtil.addSuccess(true);
    }
    @ApiOperation(value="删除", notes="删除")
    @RequestMapping(value="/{deptId}", method = RequestMethod.DELETE)
    public ResponseUtil.Result<Boolean> delete(@PathVariable("deptId") Long deptId){
    	service.removeById(deptId);
        return ResponseUtil.addSuccess(true);
    }
    
    @ApiOperation(value="查询部门树", notes="查询部门树")
    @GetMapping("/deptTree")
    public ResponseUtil.Result<List<TreeNode>> deptTree(){
    	return ResponseUtil.addSuccess(service.selectDeptTreeList());
    }

}
